package models;
import java.util.HashMap;
import java.util.Map;


public class Tables {
	private static HashMap<Long, PlayTable> plays;
	private static HashMap<Long, String> tablesNames;
	private static long nextId;
	
	public static long addTable(PlayTable table) {
		if(table == null) throw new NullPointerException();
		if(plays.containsKey(nextId)) return 0; // nieistniejacy stol
		plays.put(nextId, table);
		tablesNames.put(nextId, table.getTableName());
		return nextId++;
	}
	
	public static boolean removeTable(long tableId) {
		if(plays.remove(tableId) == null) return false;
		tablesNames.remove(tableId);
		return true;
	}
	
	public static void removeAllTables() {
		plays.clear();
		tablesNames.clear();
		nextId = 1;
	}
	
	public static Map<Long, String> getTablesIDsAndNames()
	{
		return (Map<Long, String>)tablesNames.clone();
	}
	
	public static Map<Long, PlayTable> getNonClonedTables()
	{
		return plays;
	}
	
	public static PlayTable getTable(long tableId) {
		return plays.get(tableId);
	}
	
	static {
		plays = new HashMap<Long, PlayTable>();
		tablesNames = new HashMap<Long, String>();
		nextId = 1;
	}
}
